package com.designType.stateType;

public class CancelledState implements OrderState {

    @Override
    public void ship(OrderContext context) {
        throw new UnsupportedOperationException("订单已取消，无法发货");
    }

    @Override
    public void receive(OrderContext context) {
        throw new UnsupportedOperationException("订单已取消，无法确认收货");
    }

    @Override
    public void cancel(OrderContext context) {
        System.out.println("订单已处于取消状态");
    }

    @Override
    public void pay(OrderContext context) {
        throw new UnsupportedOperationException("订单已取消，无法再次支付");
    }
}
package com.designType.stateType;

public class PaidState implements OrderState {
    @Override
    public void ship(OrderContext context) {
        System.out.println("商品已发货");
        context.setState(new ShippedState());
    }

    @Override
    public void receive(OrderContext context) {

    }

    @Override
    public void cancel(OrderContext context) {
        System.out.println("发起退款流程");
        context.setState(new CancelledState());
    }

    // 其他操作处理
    @Override
    public void pay(OrderContext context) {
        throw new UnsupportedOperationException("已支付状态不能重复支付");
    }
}
